/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
    let pricesLen = prices.length,
        res = 0,
        left = null;

    for (let i = 0; i < pricesLen; i++) {
        if (prices[i] < prices[i + 1] && left === null) {
            left = prices[i]
        }
        if(left!== null && (prices[i] > prices[i+1] || i === pricesLen - 1)){
            res+= prices[i] - left
            left = null
        }
    }

    return res;
};



/**
 * 贪心，只加连续正值
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
    let pricesLen = prices.length,
        res = 0;

    for (let i = 1; i < pricesLen; i++) {
        res += Math.max(prices[i] - prices[i - 1], 0)
    }

    return res
};